From c7201afb0cf207a7058bab72c735fc247fe612ff Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Sun, 18 Jul 2004 16:37:38 +0000 Subject: [PATCH] bitkeeper revision 1.1106.1.1 (40faa752Kdxq9bbMRBdZigZQR4lssw) Add iopl virtualisation to Linux 2.6. ioport.c is shared with 2.4. --- .rootkeys | 2 +- .../arch/xen/kernel/ioport.c | 48 ------------------ linux-2.4.26-xen-sparse/mkbuildtree | 1 + .../arch/xen/i386/kernel/ioport.c | 49 +++++++++++++++++++ .../arch/xen/i386/kernel/process.c | 13 +++++ .../arch/xen/i386/kernel/setup.c | 11 +++++ .../include/asm-xen/asm-i386/processor.h | 1 + 7 files changed, 76 insertions(+), 49 deletions(-) delete mode 100644 linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c create mode 100644 linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c diff --git a/.rootkeys b/.rootkeys index 19a5f1a5ba..da6f19bdda 100644 --- a/.rootkeys +++ b/.rootkeys @@ -80,7 +80,6 @@ 3e5a4e65ibVQmwlOn0j3sVH_j_6hAg linux-2.4.26-xen-sparse/arch/xen/kernel/evtchn.c 3e5a4e65Hy_1iUvMTPsNqGNXd9uFpg linux-2.4.26-xen-sparse/arch/xen/kernel/head.S 3e5a4e65RMGcuA-HCn3-wNx3fFQwdg linux-2.4.26-xen-sparse/arch/xen/kernel/i386_ksyms.c -3e5a4e65MEvZhlr070sK5JsfAQlv7Q linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c 3e5a4e653U6cELGv528IxOLHvCq8iA linux-2.4.26-xen-sparse/arch/xen/kernel/irq.c 3e5a4e65muT6SU3ck47IP87Q7Ti5hA linux-2.4.26-xen-sparse/arch/xen/kernel/ldt.c 4051db84bZeRX7a_Kh6VyyDuT5FOIg linux-2.4.26-xen-sparse/arch/xen/kernel/pci-dma.c @@ -164,6 +163,7 @@ 40f56238xFQe9T7M_U_FItM-bZIpLw linux-2.6.7-xen-sparse/arch/xen/i386/kernel/evtchn.c 40f56238bnvciAuyzAiMkdzGErYt1A linux-2.6.7-xen-sparse/arch/xen/i386/kernel/head.S 40f58a0d31M2EkuPbG94ns_nOi0PVA linux-2.6.7-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c +40faa751_zbZlAmLyQgCXdYekVFdWA linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c 40f562382aC3_Gt4RG-4ZsfvDRUg3Q linux-2.6.7-xen-sparse/arch/xen/i386/kernel/irq.c 40f56238ue3YRsK52HG7iccNzP1AwQ linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ldt.c 40f56238a8iOVDEoostsbun_sy2i4g linux-2.6.7-xen-sparse/arch/xen/i386/kernel/process.c diff --git a/linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c b/linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c deleted file mode 100644 index fc0164045f..0000000000 --- a/linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include -#include - - -asmlinkage int sys_iopl(unsigned int new_io_pl) -{ - unsigned int old_io_pl = current->thread.io_pl; - dom0_op_t op; - - if ( !(start_info.flags & SIF_PRIVILEGED) ) - return -EPERM; - - if ( new_io_pl > 3 ) - return -EINVAL; - - /* Need "raw I/O" privileges for direct port access. */ - if ( (new_io_pl > old_io_pl) && !capable(CAP_SYS_RAWIO) ) - return -EPERM; - - /* Maintain OS privileges even if user attempts to relinquish them. */ - if ( (new_io_pl == 0) && (start_info.flags & SIF_PRIVILEGED) ) - new_io_pl = 1; - - /* Change our version of the privilege levels. */ - current->thread.io_pl = new_io_pl; - - /* Force the change at ring 0. */ - op.cmd = DOM0_IOPL; - op.u.iopl.domain = DOMID_SELF; - op.u.iopl.iopl = new_io_pl; - HYPERVISOR_dom0_op(&op); - - return 0; -} - - -asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on) -{ - printk(KERN_INFO "ioperm not fully supported - %s\n", - turn_on ? "set iopl to 3" : "ignore resource release"); - return turn_on ? sys_iopl(3) : 0; -} - - diff --git a/linux-2.4.26-xen-sparse/mkbuildtree b/linux-2.4.26-xen-sparse/mkbuildtree index 1b86a3b4bf..5dba6c03d5 100755 --- a/linux-2.4.26-xen-sparse/mkbuildtree +++ b/linux-2.4.26-xen-sparse/mkbuildtree @@ -209,6 +209,7 @@ ln -sf ../../i386/kernel/pci-i386.h ln -sf ../../i386/kernel/ptrace.c ln -sf ../../i386/kernel/semaphore.c ln -sf ../../i386/kernel/sys_i386.c +ln -sf ../../../${LINUX_26}/arch/xen/i386/kernel/ioport.c cd ../lib ln -sf ../../i386/lib/checksum.S ln -sf ../../i386/lib/dec_and_lock.c diff --git a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c new file mode 100644 index 0000000000..13b1cfffc2 --- /dev/null +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +asmlinkage long sys_iopl(unsigned int new_io_pl) +{ + unsigned int old_io_pl = current->thread.io_pl; + dom0_op_t op; + + if (!(start_info.flags & SIF_PRIVILEGED)) + return -EPERM; + + if (new_io_pl > 3) + return -EINVAL; + + /* Need "raw I/O" privileges for direct port access. */ + if ((new_io_pl > old_io_pl) && !capable(CAP_SYS_RAWIO)) + return -EPERM; + + /* Maintain OS privileges even if user attempts to relinquish them. */ + if (new_io_pl == 0) + new_io_pl = 1; + + /* Change our version of the privilege levels. */ + current->thread.io_pl = new_io_pl; + + /* Force the change at ring 0. */ + op.cmd = DOM0_IOPL; + op.u.iopl.domain = DOMID_SELF; + op.u.iopl.iopl = new_io_pl; + HYPERVISOR_dom0_op(&op); + + return 0; +} + +asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) +{ + printk(KERN_INFO "ioperm not fully supported - %s\n", + turn_on ? "set iopl to 3" : "ignore resource release"); + return turn_on ? sys_iopl(3) : 0; +} diff --git a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/process.c b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/process.c index 1d7f637a66..c2642854fe 100644 --- a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/process.c +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/process.c @@ -338,6 +338,7 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp, struct pt_regs * childregs; struct task_struct *tsk; int err; + unsigned long eflags; childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p->thread_info)) - 1; struct_cpy(childregs, regs); @@ -386,6 +387,10 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp, desc->b = LDT_entry_b(&info); } + + __asm__ __volatile__ ( "pushfl; popl %0" : "=r" (eflags) : ); + p->thread.io_pl = (eflags >> 12) & 3; + err = 0; out: if (err && p->thread.io_bitmap_ptr) @@ -532,6 +537,14 @@ struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct tas */ load_TLS(next, cpu); + if (start_info.flags & SIF_PRIVILEGED) { + dom0_op_t op; + op.cmd = DOM0_IOPL; + op.u.iopl.domain = DOMID_SELF; + op.u.iopl.iopl = next->io_pl; + HYPERVISOR_dom0_op(&op); + } + local_irq_restore(flags); /* diff --git a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/setup.c b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/setup.c index 55a4a843d9..097828f29c 100644 --- a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/setup.c +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/setup.c @@ -1206,6 +1206,17 @@ void __init setup_arch(char **cmdline_p) conswitchp = &dummy_con; #endif #endif + + /* If we are a privileged guest OS then we should request IO privs. */ + if (start_info.flags & SIF_PRIVILEGED) { + dom0_op_t op; + op.cmd = DOM0_IOPL; + op.u.iopl.domain = DOMID_SELF; + op.u.iopl.iopl = 1; + if (HYPERVISOR_dom0_op(&op) != 0) + panic("Unable to obtain IOPL, despite SIF_PRIVILEGED"); + current->thread.io_pl = 1; + } } #include "setup_arch_post.h" diff --git a/linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/processor.h b/linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/processor.h index 6502baa35f..a57533dd8a 100644 --- a/linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/processor.h +++ b/linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/processor.h @@ -422,6 +422,7 @@ struct thread_struct { unsigned long esp; unsigned long fs; unsigned long gs; + unsigned int io_pl; /* Hardware debugging registers */ unsigned long debugreg[8]; /* %%db0-7 debug registers */ /* fault info */ -- 2.30.2